
$identify("org/mathdox/formulaeditor/modules/permutation1/left_compose.js");

$require("org/mathdox/parsing/ParserGenerator.js");
$require("org/mathdox/formulaeditor/parsing/openmath/OpenMathParser.js");
$require("org/mathdox/formulaeditor/parsing/expression/ExpressionParser.js");
$require("org/mathdox/formulaeditor/semantics/MultaryOperation.js");
$require("org/mathdox/formulaeditor/semantics/Keyword.js");

$main(function(){

  var symbol = {
    onscreen : "∘",
    openmath : null, // use default with model:cd and model:name
    mathml   : "<mo>∘</mo>"
  };

  /**
   * Define a semantic tree node that represents permutation1.left_compose.
   */
  org.mathdox.formulaeditor.semantics.Permutation1Left_compose =
    $extend(org.mathdox.formulaeditor.semantics.MultaryOperation, {

      symbol : {

        onscreen : symbol.onscreen,
        openmath : "<OMS cd='permutation1' name='left_compose'/>",
        mathml   : symbol.mathml

      },

      precedence : 130

    });
  
  /**
   * Extend the OpenMathParser object with parsing code for permutation1.left_compose.
   */
  org.mathdox.formulaeditor.parsing.openmath.OpenMathParser =
    $extend(org.mathdox.formulaeditor.parsing.openmath.OpenMathParser, {

    /**
     * Returns an equality object based on the OpenMath node.
     */
    handlePermutation1Left_compose : function(node) {

      // parse the children of the OMA
      var children = node.getChildNodes();
      var operands = [];
      for (var i=1; i<children.length; i++) {
        operands.push(this.handle(children.item(i)));
      }

      // construct the corresponding object
      var result = new org.mathdox.formulaeditor.semantics.Permutation1Left_compose();
      result.initialize.apply(result, operands);
      return result;

    }

  });

  org.mathdox.formulaeditor.parsing.openmath.KeywordList["permutation1__left_compose"] = new org.mathdox.formulaeditor.semantics.Keyword("permutation1", "left_compose", symbol, "infix");

  /**
   * Extend the ExpressionParser object with parsing code for the equality sign.
   */
  var semantics = org.mathdox.formulaeditor.semantics;
  var pG = new org.mathdox.parsing.ParserGenerator();

  if ( "∘" == "∘" ) {
    // only one expression, same on screen
    org.mathdox.formulaeditor.parsing.expression.ExpressionParser =
      $extend(org.mathdox.formulaeditor.parsing.expression.ExpressionParser, {

      // expression130 = left_compose | super.expression130
      expression130 : function() {
        var parent = arguments.callee.parent;
        pG.alternation(
          pG.rule("permutation1left_compose"),
          parent.expression130).apply(this, arguments);
      },

      // permutation1left_compose = 
      //    expression130 "∘" expression140
      permutation1left_compose :
        pG.transform(
          pG.concatenation(
            pG.rule("expression130"),
            pG.literal("∘"),
            pG.rule("expression140")
          ),
          function(result) {
            return new semantics.Permutation1Left_compose(result[0], result[2]);
          }
        )

      });
    } else { // allow alternative as displayed on the screen
      org.mathdox.formulaeditor.parsing.expression.ExpressionParser =
        $extend(org.mathdox.formulaeditor.parsing.expression.ExpressionParser, {

        // expression130 = permutation1left_compose | 
        //   permutation1left_composealt | super.expression130
        expression130 : function() {
          var parent = arguments.callee.parent;
          pG.alternation(
            pG.rule("permutation1left_compose"),
            pG.rule("permutation1left_composealt"),
            parent.expression130).apply(this, arguments);
        },

        // permutation1left_compose = 
        //    expression130 "∘" expression140
        permutation1left_compose :
          pG.transform(
            pG.concatenation(
              pG.rule("expression130"),
              pG.literal("∘"),
              pG.rule("expression140")
            ),
            function(result) {
              return new semantics.Permutation1Left_compose(result[0], result[2]);
            }
          ),

        // permutation1left_composealt = 
        //    expression130 "∘" expression140
        permutation1left_composealt :
          pG.transform(
            pG.concatenation(
              pG.rule("expression130"),
              pG.literal("∘"),
              pG.rule("expression140")
            ),
            function(result) {
              return new semantics.Permutation1Left_compose(result[0], result[2]);
            }
          )

      });
    }

});
